#include "GowildResponseRoomListCmd.h"

GowildResponseRoomListCmd::GowildResponseRoomListCmd(QObject *parent) :
    BaseCmd(parent)
{
    this->m_protocolType = ProtocolType::GowildProtocol;
    this->m_functionCode = FunctionCode;
}

Package GowildResponseRoomListCmd::toPackage()
{
    Package package;

    QVariantMap jsonData;
    jsonData.insert("type","RESPONSE_ROOM");

    QVariantList dataList;
    QList<int> roomIdList = m_roomHash.keys();
    for(int i=0; i<roomIdList.size(); i++)
    {
        QVariantMap data;
        int roomId = roomIdList.at(i);
        QString roomName = m_roomHash.value(roomId);
        data.insert("id",QString::number(roomId,10));
        data.insert("name",roomName);
        dataList.append(data);
    }
    jsonData.insert("data",dataList);

    QJson::Serializer serializer;
    QByteArray body = serializer.serialize(jsonData, NULL);

    package.setBody(body);
    package.setFunction(FunctionCode);

    return package;
}

void GowildResponseRoomListCmd::unPackage(Package package)
{
    Q_UNUSED(package);
}
QHash<int, QString> GowildResponseRoomListCmd::roomHash() const
{
    return m_roomHash;
}

void GowildResponseRoomListCmd::setRoomHash(const QHash<int, QString> &roomHash)
{
    m_roomHash = roomHash;
}

